let webpack = require('webpack');
let path = require('path');
let ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
    entry: {
        main: path.resolve(__dirname, './js/main.js'),
    },
    output: {
        path: path.resolve(__dirname, './dist'),
        publicPath: '/dist/',
        filename: '[name].js',
    },
    module: {
        rules: [
            {
                test: /\.pcss$/,
                use: ExtractTextPlugin.extract({
                    fallback: 'style-loader',
                    use: [
                        {
                            loader: 'css-loader',
                            options: {
                                modules: true,
                                importLoaders: 1,
                                localIdentName: '[name]__[local]___[hash:base64:5]',
                            },
                        },
                        {
                            loader: 'postcss-loader',
                            options: {
                                parser: 'sugarss',
                                exec: true,
                            },
                        },
                    ],
                }),
            },
            {
                test: /\.css$/,
                use: [
                    {
                        loader: 'style-loader',

                    }, {
                        loader: 'css-loader',
                    },
                ],
            },
            {
                test: /\.rt$/,
                use: {
                    loader: 'react-templates-loader',
                    options: {
                        modules: 'commonjs',
                    },
                },
            },
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['react', 'env', 'es2015', 'stage-0'],
                        plugins: ['transform-runtime'],
                    },
                },
            }, {
                test: /\.(png|jpg|gif)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 8192,
                        name: '/image/[name][hash:8].[ext]',
                        prefix: 'img',
                    },
                },

            }, {
                test: /\.(eot|woff|woff2|svg|ttf)([\?]?.*)$/,
                use: {
                    loader: 'file-loader',
                    options: {
                        limit: 8192,
                        name: '/fonts/[name][hash:8].[ext]',
                    },
                },
            },
        ],
    },
    devtool: 'source-map',
    plugins: [
        new ExtractTextPlugin('[name].css', {
            allChunks: true,
        }),
        new webpack.NoErrorsPlugin(),
        // new webpack.LoaderOptionsPlugin({
        //
        // }),
        new webpack.ProvidePlugin({
            '$': 'jquery',
            'jQuery': 'jquery',
            'window.jQuery': 'jquery',
            'tether': 'tether',
            'Tether': 'tether',
            'window.Tether': 'tether',
        }),
    ],
};
